#! /usr/bin/perl -w
use strict;
use File::Find();

use vars qw/*name *dir *prune/;

*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;

sub wanted;

#File::Find::find({wanted => \&wanted},'.');
File::Find::find(\&wanted,'.');
exit;

sub process_file {
	my $cur_dir = $_[0];
	my $ori_filename = $_[1];
	my $bak_filename = $_[1].".bak";
	if(!open MONKEYF ,'<',$ori_filename){
	    die "Cannot open $ori_filename";
   	 }
   	 if(!open BAK_MONKEYF ,'>',$bak_filename){
       		 die "Cannot open $bak_filename";
	}
	while( <MONKEYF> ){
	    if(m/(Common.AHT)/){
	            s/$1/AudioHAL.AHT/g;
		    print $_;
	    }
	    print BAK_MONKEYF $_;
	}
	close BAK_MONKEYF;
	close MONKEYF;
	if((unlink $ori_filename) == 1){
	    rename $bak_filename,$ori_filename;
	    unlink $bak_filename;
	    print "Substitute file OK!\n";
	}
}

sub wanted {
	/^.*\.py\z/s
#&& print("$name\n");
	&& &process_file($dir,$_);
}
